import request from '/@/utils/request';
import other from '/@/utils/other';
import { AxiosResponse } from 'axios';
import { ISysWarehouseLocation, ISysWarehouseLocationView, ISysWarehouseLocationVm } from '/@/views/supplychain/syswarehouselocation/api/interface';
import { IResult } from '/@/types/common';

interface ISysWarehouseLocationApi {
	search(data: object): Promise<AxiosResponse<ISysWarehouseLocationView[]>>;
	get(id: string | number): Promise<AxiosResponse<ISysWarehouseLocationVm>>;
	add(data: ISysWarehouseLocationVm): Promise<AxiosResponse<ISysWarehouseLocation>>;
	edit(data: ISysWarehouseLocationVm): Promise<AxiosResponse<ISysWarehouseLocation>>;
	batchEdit(data: object): Promise<AxiosResponse>;
	delete(ids: (string | number)[]): Promise<AxiosResponse<number>>;
	export(data: object): Promise<void>;
	exportById(ids: (string | number)[]): Promise<void>;
	import(data: object): Promise<AxiosResponse<number>>;
	approve(data: object, tag: string): Promise<AxiosResponse<any, any>>;
	sync(): Promise<AxiosResponse>;
}

function SysWarehouseLocationApi(): ISysWarehouseLocationApi {
	return {
		async search(data: object): Promise<AxiosResponse<ISysWarehouseLocationView[]>> {
			return await request({
				url: '/api/SysWarehouseLocation/Search',
				method: 'post',
				data,
			});
		},
		async get(id: string | number): Promise<AxiosResponse<ISysWarehouseLocationVm>> {
			return await request({
				url: `/api/SysWarehouseLocation/${id}`,
				method: 'get',
			});
		},
		async add(data: ISysWarehouseLocationVm): Promise<AxiosResponse<ISysWarehouseLocation>> {
			return await request({
				url: '/api/SysWarehouseLocation/Add',
				method: 'post',
				data,
			});
		},
		async edit(data: ISysWarehouseLocationVm): Promise<AxiosResponse<ISysWarehouseLocation>> {
			return await request({
				url: '/api/SysWarehouseLocation/Edit',
				method: 'put',
				data,
			});
		},
		async batchEdit(data: object): Promise<AxiosResponse> {
			return await request({
				url: '/api/SysWarehouseLocation/batchEdit',
				method: 'post',
				data,
			});
		},
		async delete(ids: (string | number)[]): Promise<AxiosResponse<number>> {
			return await request({
				url: '/api/SysWarehouseLocation/BatchDelete',
				method: 'post',
				data: ids,
			});
		},
		async export(data: object): Promise<void> {
			const response = await request<any, Blob>({
				responseType: 'blob',
				url: '/api/SysWarehouseLocation/ExportExcel',
				method: 'post',
				data,
			});
			other.downloadFile(response);
		},
		async exportById(ids: (string | number)[]): Promise<void> {
			const response = await request<any, Blob>({
				responseType: 'blob',
				url: '/api/SysWarehouseLocation/ExportExcelByIds',
				method: 'post',
				data: ids,
			});
			other.downloadFile(response);
		},
		async import(data: object): Promise<AxiosResponse<number>> {
			return await request({
				url: '/api/SysWarehouseLocation/Import',
				method: 'post',
				data,
			});
		},
		async approve(data: object, tag: string) {
			return request({
				url: '/api/SysWarehouseLocation/approve?tag=' + tag,
				method: 'post',
				data,
			});
		},
		async sync(): Promise<AxiosResponse> {
			return await request({
				url: `/api/SysWarehouseLocation/Sync`,
				method: 'get',
			});
		},
	};
}

export { SysWarehouseLocationApi };
